﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSModel;
using TTSBLL;
using TTS;

public partial class Repair_DM_DM_T0002368SN : System.Web.UI.Page
{
    private Assemble assemble_T0002040;
    private AssembleItem assembleItem_T0002040;
    private string message;
    private string sn { get { return ViewState["sn"].ToString(); } set { ViewState["sn"] = value; } }
    private const string storedProcedureName = "DMAssembly_delete";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.T0002368_inputSN.Focus();
    }

    public Repair_DM_DM_T0002368SN()
    {
        assemble_T0002040 = new Assemble();
        assembleItem_T0002040 = new AssembleItem();
    }
    protected void T0002368_inputSN_TextChanged(object sender, EventArgs e)
    {
        sn = this.T0002368_inputSN.Text.Trim();
        if (SNHelper.SNCheck(sn, "T0002368", out message))
        {          
                if (assemble_T0002040.Assemble_SNAlreadyExist(sn))
                {
                    AssembleInfo ainfo = assemble_T0002040.Assemble_GetbySN(sn);

                    if (assembleItem_T0002040.AssembleItem_GetbyID(ainfo.ID).Count == 1)
                    {
                        this.Repair.Enabled = true;
                        this.Repair.Focus();
                    }
                    else
                    {
                        message = "请选择DM整机解锁！";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                        this.T0002368_inputSN.Text = "";
                    }

                }
                else
                {
                    message = "该" + sn + "在数据库中不存在装配记录，请重新扫描正确的SN号！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                    this.T0002368_inputSN.Text = "";
                }          
        }
        else
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        }
    }
    protected void Repair_Click(object sender, EventArgs e)
    {
        assemble_T0002040.AssembleDeleteBySN(sn, storedProcedureName);
        message = "装配关系解锁成功！";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.T0002368_inputSN.Text = "";
        this.Repair.Enabled = false;
    }
    protected void Return_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Repair/DM/DMRepairHtml.aspx");
    }
}